package com.orchard.xpz.controller.pesticidesBuy;

import com.orchard.xpz.entity.pesticidesBuy.PesticidesBuy;
import com.orchard.xpz.entity.plantFood.PlantFood;
import com.orchard.xpz.service.pesticidesBuy.PesticidesBuyService;
import com.orchard.xpz.utils.PageResultData;
import com.orchard.xpz.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @TaskCode:
 * @description:
 * @author: minshuai.chen
 * @create: 2022/4/19 11:09
 **/
@RestController
@RequestMapping("/pesticidesBuy")
public class PesticidesBuyController {
    @Autowired
    private PesticidesBuyService pesticidesBuyService;

    @RequestMapping("/getPageList")
    public R<PageResultData<PesticidesBuy>> getPageList(@RequestBody PesticidesBuy gardenPlot){
        return R.success(pesticidesBuyService.getPageList(gardenPlot));
    }

    @RequestMapping("/saveOrUpdate")
    public R<String> saveOrUpdate(@RequestBody PesticidesBuy gardenPlot){
        if (pesticidesBuyService.saveOrUpdate(gardenPlot)){
            return R.success("success");
        }else{
            return R.fail("error");
        }
    }

    @RequestMapping("/delete")
    public R<String> delete(@RequestParam("id") String id){
        if (pesticidesBuyService.deltePlot(id)){
            return R.success("success");
        }else{
            return R.fail("error");
        }
    }

    @RequestMapping("/getList")
    public R<List<PesticidesBuy>> getLst(@RequestBody PesticidesBuy plantFood){
        plantFood.setPageNum(1);
        plantFood.setPageSize(10000);
        List<PesticidesBuy> rows = pesticidesBuyService.getCountList(plantFood);
        return R.success(rows);
    }
}
